home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Apple Development Tools / MacsBug 6.5.4a6.sit / MacsBug 6.5.4a6 / Building dcmds / Pascal Samples / Echo.p next >
Text File  |  1998-09-22  |  3KB  |  117 lines

  1. {
  2.  
  3.     File:        Echo.p
  4.  
  5.     Contains:    Pascal source for the Echo dcmd
  6.  
  7.     Written by:    JM3 = Jim Murphy
  8.  
  9.     Copyright:    © 1994 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.          <2>   14-Dec-94    JM3        Updated to support the new format 3 dcmd requirements.
  14.  
  15. }
  16.  
  17. UNIT Echo;
  18.  
  19. (* The following MPW commands will build the dcmd and copy it to the
  20.    "Debugger Prefs" file in the System folder. The dcmd's name in
  21.          MacsBug will be the name of the file built by the Linker.
  22.  
  23.         Pascal Echo.p
  24.         Link dcmdGlue.a.o Echo.p.o {Libraries}Runtime.o {PLibraries}PasLib.o -o Echo
  25.         BuildDcmd Echo 101
  26.                     Echo 'include "Echo";'            |            Rez -a -o "{systemFolder}Debugger Prefs"
  27. *)
  28.  
  29. {$R-}
  30.  
  31. INTERFACE
  32.  
  33.         USES MemTypes, dcmd;
  34.         
  35.   { Public declaration for dcmdGlue. Must be in every dcmd. The name cannot be changed. }
  36.         PROCEDURE CommandEntry (paramPtr: dcmdBlockPtr);
  37.  
  38.  
  39. IMPLEMENTATION
  40.  
  41. CONST CR = $0D;
  42.  
  43.  
  44. PROCEDURE NumberToHex (number: LONGINT; VAR hex: Str255);
  45. VAR digits: Str255;
  46.     n: INTEGER;
  47. BEGIN
  48.     digits := '0123456789ABCDEF';
  49.     hex := '00000000';
  50.     FOR n := 8 DOWNTO 1 DO
  51.         BEGIN
  52.         hex[n] := digits[1 + (number MOD 16)];
  53.         number := number DIV 16;
  54.         END;
  55. END;
  56.  
  57.  
  58. PROCEDURE CommandEntry (paramPtr: DCmdBlockPtr);
  59. VAR pos:   INTEGER;
  60.     ch:    CHAR;
  61.                 value: LONGINT;
  62.                 ok:    BOOLEAN;
  63.                 str:   Str255;
  64. BEGIN
  65.     IF paramPtr^.request = dcmdInit THEN
  66.           BEGIN { The dcmd gets called once when loaded to init itself }
  67.         END
  68.     ELSE
  69.     IF paramPtr^.request = dcmdDoIt THEN
  70.         BEGIN { Do the command's normal function }
  71.         dcmdDrawLine ('Echoing parameters');
  72.  
  73.         REPEAT
  74.             { Save the position so we can rewind if we get an error }
  75.             pos := dcmdGetPosition;
  76.             ch  := dcmdPeekAtNextChar;
  77.             IF ch IN ['A'..'Z', 'a'..'z'] THEN
  78.                 BEGIN { Get the parameter as a text string }
  79.                 ch := dcmdGetNextParameter (str);
  80.                 dcmdDrawLine (str);
  81.                 END
  82.             ELSE
  83.                 BEGIN { Get the parameter as a 32 bit value }
  84.                     ch := dcmdGetNextExpression (value, ok);
  85.                     IF ok THEN
  86.                         BEGIN { The expression was parsed correctly }
  87.                         NumberToHex  (value, str);
  88.                         dcmdDrawLine (str);
  89.                         END
  90.                     ELSE
  91.                         BEGIN { The expression contained an error. Get it as a string }
  92.                         dcmdSetPosition (pos);
  93.                         ch := dcmdGetNextParameter (str);
  94.                         dcmdDrawLine (str);
  95.                         END;
  96.                 END;
  97.         UNTIL ch = CHR(CR);
  98.         END
  99.     ELSE IF paramPtr^.request = dcmdHelp THEN { Display the command's help information }
  100.         BEGIN
  101.             dcmdDrawLine ('Echo the command line parameters.');
  102.         END
  103.     ELSE IF paramPtr^.request = dcmdGetInfo THEN
  104.         BEGIN { Return the command's usage information and version so MacsBug can draw them }
  105.         GetInfoRequestBlockPtr(paramPtr^.requestIOBlock)^.usageStr := '[params...]';
  106.  
  107.         { Set the version to 3.0 final. }
  108.  
  109.         GetInfoRequestBlockPtr(paramPtr^.requestIOBlock)^.dcmdVersion.majorRev := $03;
  110.         GetInfoRequestBlockPtr(paramPtr^.requestIOBlock)^.dcmdVersion.minorAndBugRev := $00;
  111.         GetInfoRequestBlockPtr(paramPtr^.requestIOBlock)^.dcmdVersion.stage := $80;
  112.         GetInfoRequestBlockPtr(paramPtr^.requestIOBlock)^.dcmdVersion.nonRelRev := $00;        
  113.         END;
  114. END;
  115.  
  116. END.
  117.